package com.wedata.抖音;

import cn.hutool.crypto.digest.MD5;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

//https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/order.query/query
//https://life.douyin.com/p/login
//后台 登录账号 18008473503 短信验证码
public class 抖音来客 {


    public static void main(String[] args) throws Exception {


        //queryGoodsPage();
        //queryGoodsInfo();
        查询订单券状态("1089284293717147158");
        //queryOrder("1088543746393305804");

        /*String result = "{\"verify_results\":[{\"account_id\":\"7011378472920713250\",\"certificate_id\":\"7527935629712326682\",\"code\":\"CgYIASAHKAESLgosQGn5QrVGmVrQ+LN588Dj8ZU7gVo1fPZ7n80HyPvEOFpsEKgr568qgcS7LUYaAA\\u003d\\u003d\",\"msg\":\"履约成功\",\"order_id\":\"1086651184322580487\",\"origin_code\":\"104627591197026\",\"result\":0,\"verify_amount_info\":{\"time_card_amount\":{\"amount\":15323},\"times_card_serial_amount\":{\"amount\":{\"coupon_pay_amount\":15323,\"list_market_amount\":39500,\"merchant_ticket_amount\":0,\"original_amount\":15334,\"pay_amount\":15323,\"platform_discount_amount\":11},\"serial_numb\":1}},\"verify_id\":\"7527937032132347931\"},{\"account_id\":\"7011378472920713250\",\"certificate_id\":\"7527935629712326682\",\"code\":\"CgYIASAHKAESLgosQGn5QrVGmVrQ+LN588Dj8ZU7gVo1fPZ7n80HyPvEOFpsEKgr568qgcS7LUYaAA\\u003d\\u003d\",\"msg\":\"履约成功\",\"order_id\":\"1086651184322580487\",\"origin_code\":\"104627591197026\",\"result\":0,\"verify_amount_info\":{\"time_card_amount\":{\"amount\":15323},\"times_card_serial_amount\":{\"amount\":{\"coupon_pay_amount\":15323,\"list_market_amount\":39500,\"merchant_ticket_amount\":0,\"original_amount\":15334,\"pay_amount\":15323,\"platform_discount_amount\":11},\"serial_numb\":2}},\"verify_id\":\"7527937032132364315\"},{\"account_id\":\"7011378472920713250\",\"certificate_id\":\"7527935629712326682\",\"code\":\"CgYIASAHKAESLgosQGn5QrVGmVrQ+LN588Dj8ZU7gVo1fPZ7n80HyPvEOFpsEKgr568qgcS7LUYaAA\\u003d\\u003d\",\"msg\":\"履约成功\",\"order_id\":\"1086651184322580487\",\"origin_code\":\"104627591197026\",\"result\":0,\"verify_amount_info\":{\"time_card_amount\":{\"amount\":15322},\"times_card_serial_amount\":{\"amount\":{\"coupon_pay_amount\":15322,\"list_market_amount\":39500,\"merchant_ticket_amount\":0,\"original_amount\":15334,\"pay_amount\":15322,\"platform_discount_amount\":12},\"serial_numb\":3}},\"verify_id\":\"7527937032132380699\"},{\"account_id\":\"7011378472920713250\",\"certificate_id\":\"7527935629712326682\",\"code\":\"CgYIASAHKAESLgosQGn5QrVGmVrQ+LN588Dj8ZU7gVo1fPZ7n80HyPvEOFpsEKgr568qgcS7LUYaAA\\u003d\\u003d\",\"msg\":\"履约成功\",\"order_id\":\"1086651184322580487\",\"origin_code\":\"104627591197026\",\"result\":0,\"verify_amount_info\":{\"time_card_amount\":{\"amount\":15322},\"times_card_serial_amount\":{\"amount\":{\"coupon_pay_amount\":15322,\"list_market_amount\":39500,\"merchant_ticket_amount\":0,\"original_amount\":15333,\"pay_amount\":15322,\"platform_discount_amount\":11},\"serial_numb\":4}},\"verify_id\":\"7527937042655905843\"},{\"account_id\":\"7011378472920713250\",\"certificate_id\":\"7527935629712326682\",\"code\":\"CgYIASAHKAESLgosQGn5QrVGmVrQ+LN588Dj8ZU7gVo1fPZ7n80HyPvEOFpsEKgr568qgcS7LUYaAA\\u003d\\u003d\",\"msg\":\"履约成功\",\"order_id\":\"1086651184322580487\",\"origin_code\":\"104627591197026\",\"result\":0,\"verify_amount_info\":{\"time_card_amount\":{\"amount\":15322},\"times_card_serial_amount\":{\"amount\":{\"coupon_pay_amount\":15322,\"list_market_amount\":39500,\"merchant_ticket_amount\":0,\"original_amount\":15333,\"pay_amount\":15322,\"platform_discount_amount\":11},\"serial_numb\":5}},\"verify_id\":\"7527937042655922227\"},{\"account_id\":\"7011378472920713250\",\"certificate_id\":\"7527935629712326682\",\"code\":\"CgYIASAHKAESLgosQGn5QrVGmVrQ+LN588Dj8ZU7gVo1fPZ7n80HyPvEOFpsEKgr568qgcS7LUYaAA\\u003d\\u003d\",\"msg\":\"履约成功\",\"order_id\":\"1086651184322580487\",\"origin_code\":\"104627591197026\",\"result\":0,\"verify_amount_info\":{\"time_card_amount\":{\"amount\":15322},\"times_card_serial_amount\":{\"amount\":{\"coupon_pay_amount\":15322,\"list_market_amount\":39500,\"merchant_ticket_amount\":0,\"original_amount\":15333,\"pay_amount\":15322,\"platform_discount_amount\":11},\"serial_numb\":6}},\"verify_id\":\"7527937042655938611\"},{\"account_id\":\"7011378472920713250\",\"certificate_id\":\"7527935629712326682\",\"code\":\"CgYIASAHKAESLgosQGn5QrVGmVrQ+LN588Dj8ZU7gVo1fPZ7n80HyPvEOFpsEKgr568qgcS7LUYaAA\\u003d\\u003d\",\"msg\":\"履约成功\",\"order_id\":\"1086651184322580487\",\"origin_code\":\"104627591197026\",\"result\":0,\"verify_amount_info\":{\"time_card_amount\":{\"amount\":15322},\"times_card_serial_amount\":{\"amount\":{\"coupon_pay_amount\":15322,\"list_market_amount\":39500,\"merchant_ticket_amount\":0,\"original_amount\":15333,\"pay_amount\":15322,\"platform_discount_amount\":11},\"serial_numb\":7}},\"verify_id\":\"7527937042655954995\"},{\"account_id\":\"7011378472920713250\",\"certificate_id\":\"7527935629712326682\",\"code\":\"CgYIASAHKAESLgosQGn5QrVGmVrQ+LN588Dj8ZU7gVo1fPZ7n80HyPvEOFpsEKgr568qgcS7LUYaAA\\u003d\\u003d\",\"msg\":\"履约成功\",\"order_id\":\"1086651184322580487\",\"origin_code\":\"104627591197026\",\"result\":0,\"verify_amount_info\":{\"time_card_amount\":{\"amount\":15322},\"times_card_serial_amount\":{\"amount\":{\"coupon_pay_amount\":15322,\"list_market_amount\":39500,\"merchant_ticket_amount\":0,\"original_amount\":15333,\"pay_amount\":15322,\"platform_discount_amount\":11},\"serial_numb\":8}},\"verify_id\":\"7527937042655971379\"},{\"account_id\":\"7011378472920713250\",\"certificate_id\":\"7527935629712326682\",\"code\":\"CgYIASAHKAESLgosQGn5QrVGmVrQ+LN588Dj8ZU7gVo1fPZ7n80HyPvEOFpsEKgr568qgcS7LUYaAA\\u003d\\u003d\",\"msg\":\"履约成功\",\"order_id\":\"1086651184322580487\",\"origin_code\":\"104627591197026\",\"result\":0,\"verify_amount_info\":{\"time_card_amount\":{\"amount\":15322},\"times_card_serial_amount\":{\"amount\":{\"coupon_pay_amount\":15322,\"list_market_amount\":39500,\"merchant_ticket_amount\":0,\"original_amount\":15333,\"pay_amount\":15322,\"platform_discount_amount\":11},\"serial_numb\":9}},\"verify_id\":\"7527937042655987763\"}],\"error_code\":0,\"description\":\"success\"}";
        JSONObject jsonObject = new  JSONObject(result);
        JSONArray verify_results = jsonObject.getJSONArray("verify_results");
        for(int i=0; i< verify_results.size() ;i++){
            JSONObject item = verify_results.getJSONObject(i);
            String verify_id = item.getStr("verify_id");
            String certificate_id = item.getStr("certificate_id");
            撤销核销(certificate_id,verify_id);
        }*/
        //撤销核销("7534908119878025268","7534925567150262314");
        //{"data":{"description":"","orders":[{"room_id":"7514945091601959714","open_id":"_000NaedYC5bA_TDik4zJbFb1Hq8yh3ZBX_n","discount_amount":800,"pay_amount":9100,"certificate":[{"combination_id":"","item_status":100,"certificate_id":"7514951884060278821","order_item_id":"800011828834430848213820487","refund_time":0,"refund_amount":0,"item_update_time":1749711091}],"count":1,"create_order_time":1749711088,"intention_poi_id":"6912240295505561600","third_sku_id":"","sku_id":"1834504829123608","pay_time":1749711091,"products":[{"num":1,"commodities":[],"sku_id":"1834504829123608","snapshot_product":{"product_attr":{"show_channel":2},"tag_info_list":[]},"product_name":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","product_id":"1834504829123608"}],"update_order_time":1749711100,"order_status":201,"discounts":[{"platform_discount_amount":100,"discount_amount":800,"merchant_discount_amount":700,"discount_type":2,"brand_discount_amount":0,"provider_discount_amount":0},{"platform_discount_amount":0,"discount_amount":0,"merchant_discount_amount":0,"discount_type":1,"brand_discount_amount":0,"provider_discount_amount":0}],"sub_order_amount_infos":[{"combination_id":"","discount_amount":800,"pay_amount":9100,"sub_order_id":"800011828834430848213820487","origin_amount":9900,"sub_order_type":100,"discounts":[{"platform_discount_amount":100,"discount_amount":800,"merchant_discount_amount":700,"discount_type":2,"brand_discount_amount":0,"provider_discount_amount":0}],"receipt_amount":9100}],"original_amount":9900,"payment_discount":0,"receipt_amount":9100,"sku_name":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","poi_id":"6912240295505561600","order_id":"1085870633719060487","order_type":21,"contacts":[{"phone":"","name":""}]}],"error_code":0,"page":{"page_num":1,"total":1,"page_size":10}},"extra":{"sub_error_code":0,"sub_description":"","description":"","now":1749720518,"error_code":0,"logid":"2025061217283764EFA538147E8105037C"}}
        //queryOrder("1089185744786263438");
        //{"data":{"description":"","orders":[{"room_id":"7520228342335867657","anchor_id":4199788844422397,"open_id":"_000XKfZGWgL2PM_yt3U3cMWNZIvoHZupZPu","discount_amount":64100,"pay_amount":5800,"certificate":[{"combination_id":"","item_status":100,"certificate_id":"7520236039860944923","order_item_id":"800011894099824512213034249","refund_time":0,"refund_amount":0,"item_update_time":1750941402}],"count":1,"create_order_time":1750941391,"intention_poi_id":"7505591628745148468","third_sku_id":"","sku_id":"1834799899575320","pay_time":1750941400,"update_order_time":1750941403,"order_status":201,"discounts":[{"platform_discount_amount":0,"discount_amount":63000,"merchant_discount_amount":63000,"discount_type":2,"brand_discount_amount":0,"provider_discount_amount":0},{"platform_discount_amount":0,"discount_amount":300,"merchant_discount_amount":300,"discount_type":1,"brand_discount_amount":0,"provider_discount_amount":0},{"platform_discount_amount":100,"discount_amount":800,"merchant_discount_amount":700,"discount_type":2,"brand_discount_amount":0,"provider_discount_amount":0},{"platform_discount_amount":0,"discount_amount":0,"merchant_discount_amount":0,"discount_type":1,"brand_discount_amount":0,"provider_discount_amount":0}],"sub_order_amount_infos":[{"combination_id":"","discount_amount":64100,"pay_amount":5800,"sub_order_id":"800011894099824512213034249","origin_amount":69900,"sub_order_type":100,"discounts":[{"platform_discount_amount":0,"discount_amount":63000,"merchant_discount_amount":63000,"discount_type":2,"brand_discount_amount":0,"provider_discount_amount":0},{"platform_discount_amount":0,"discount_amount":300,"merchant_discount_amount":300,"discount_type":1,"brand_discount_amount":0,"provider_discount_amount":0},{"platform_discount_amount":100,"discount_amount":800,"merchant_discount_amount":700,"discount_type":2,"brand_discount_amount":0,"provider_discount_amount":0}],"receipt_amount":5800}],"original_amount":69900,"payment_discount":0,"receipt_amount":5800,"sku_name":"【南部新城新店专属】7天3节一对一私教 当天拍下联系客服加赠好礼（江苏限定）","poi_id":"7505591628745148468","order_id":"1086151485284824249","order_type":51,"contacts":[{"phone_encrypt":"","phone":"186****5745","name":""}]}],"error_code":0,"page":{"page_num":1,"total":1,"page_size":10}},"extra":{"sub_error_code":0,"sub_description":"","description":"","now":1750992631,"error_code":0,"logid":"2025062710503033D3731E2ABE7887CC5B"}}

        //queryOrder("1086296692075546433");
        //{"data":{"description":"","orders":[{"open_id":"_000lq5yaEBm30setM7MlsVnLkf-9Db2ykDr","discount_amount":0,"pay_amount":10900,"certificate":[{"combination_id":"","item_status":100,"certificate_id":"7520246401826062377","order_item_id":"800011880549936870613235257","refund_time":0,"refund_amount":0,"item_update_time":1750943814}],"count":1,"create_order_time":1750943810,"intention_poi_id":"6962644565459208232","third_sku_id":"","sku_id":"1827098036461612","pay_time":1750943813,"update_order_time":1750943821,"order_status":201,"sub_order_amount_infos":[{"combination_id":"","discount_amount":0,"pay_amount":10900,"sub_order_id":"800011880549936870613235257","origin_amount":10900,"sub_order_type":100,"discounts":[],"receipt_amount":10900}],"original_amount":10900,"payment_discount":0,"receipt_amount":10900,"sku_name":"【联系客服约课】7天3节一对一私教课  全新用户专享（长沙主页限定）","poi_id":"6962644565459208232","order_id":"1086161182491865257","order_type":51,"contacts":[{"phone_encrypt":"","phone":"130****8016","name":""}]}],"error_code":0,"page":{"page_num":1,"total":1,"page_size":10}},"extra":{"sub_error_code":0,"sub_description":"","description":"","now":1750992915,"error_code":0,"logid":"20250627105515796FF990577C7E877F24"}}

        //{"data":{"description":"","orders":[{"open_id":"_0002FfEYgTmcyNvV9NYntN0GlzgIj_PHmGn","discount_amount":1,"pay_amount":9899,"certificate":[{"combination_id":"","item_status":100,"certificate_id":"7520206416704438307","order_item_id":"800011889177117773013106819","refund_time":0,"refund_amount":0,"item_update_time":1750934504}],"count":1,"create_order_time":1750934497,"intention_poi_id":"7312001208142317578","third_sku_id":"","sku_id":"1830515852675124","pay_time":1750934502,"update_order_time":1750934508,"order_status":201,"discounts":[{"platform_discount_amount":0,"discount_amount":1,"merchant_discount_amount":0,"discount_type":3,"brand_discount_amount":0,"provider_discount_amount":0}],"sub_order_amount_infos":[{"combination_id":"","discount_amount":1,"pay_amount":9899,"sub_order_id":"800011889177117773013106819","origin_amount":9900,"sub_order_type":100,"discounts":[{"platform_discount_amount":0,"discount_amount":1,"merchant_discount_amount":0,"discount_type":3,"brand_discount_amount":0,"provider_discount_amount":0}],"receipt_amount":9900}],"original_amount":9900,"payment_discount":1,"receipt_amount":9900,"sku_name":"【联系客服约课】热店优惠 7天3节一对一私教课 全新用户专享（江苏主页限定）","order_id":"1086155628222746819","order_type":51,"contacts":[{"phone_encrypt":"","phone":"188****1586","name":""}]}],"error_code":0,"page":{"page_num":1,"total":1,"page_size":10}},"extra":{"sub_error_code":0,"sub_description":"","description":"","now":1750993148,"error_code":0,"logid":"202506271059087D538F0CFC69C78B5575"}}

        //查询订单券状态("1085870633719060487");//1021701397286745879
        //{"data":{"certificates_v2":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900},"encrypted_code":"CgYIASAHKAESLgosdgsZ57FXFwTOEPgwbJvQnb1i++JNm4Kly0b7MTL6QDRp4t7sW/IeYJ6OqH8aAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1},"status":1}],"description":"success","certificates":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900},"encrypted_code":"CgYIASAHKAESLgosdgsZ57FXFwTOEPgwbJvQnb1i++JNm4Kly0b7MTL6QDRp4t7sW/IeYJ6OqH8aAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1},"status":1}],"error_code":0},"extra":{"sub_error_code":0,"sub_description":"","description":"success","now":1749720518,"error_code":0,"logid":"20250612172838E623427EA0D25405A99C"}}

        //验券准备("107649093776322");
        //验券准备("106130810012194");
        //{"data":{"certificates_v2":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900,"brand_ticket_amount":0},"encrypted_code":"CgYIASAHKAESLgos1/nAZVUlsABtLbCMMmuq3ND5YRciIRJ9m4PSXDDgvigLtP6cygDEVXru8NoaAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1}}],"description":"success","verify_token":"dbc84655-c43f-46e2-84b1-d15e3a53b934","certificates":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900,"brand_ticket_amount":0},"encrypted_code":"CgYIASAHKAESLgosJQi0GPIBmQLzy23xLALjVEU11XHa7/pZJkRw2l54JT6wyGoIW8yw69sLcigaAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1}}],"error_code":0,"order_id":"1085870633719060487"},"extra":{"sub_error_code":0,"sub_description":"","description":"success","now":1749711188,"error_code":0,"logid":"2025061214530808975114F25E6690B319"}}
        //{"data":{"certificates_v2":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900,"brand_ticket_amount":0},"encrypted_code":"CgYIASAHKAESLgosyGPjPh+ZJ2qqhvyEarRQ+lfYixWd6R8N9+xRlUguXdUS3rFTClFP4EyRbyYaAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1}}],"description":"success","verify_token":"419add29-05be-404e-83b8-68a6dce930b6","certificates":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900,"brand_ticket_amount":0},"encrypted_code":"CgYIASAHKAESLgoscB0qTgACX/MLEUCldZObO19YT3+8zSsgTImF5nB5l+Gs1EeHmtyDIxd/dykaAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1}}],"error_code":0,"order_id":"1085870633719060487"},"extra":{"sub_error_code":0,"sub_description":"","description":"success","now":1749711298,"error_code":0,"logid":"20250612145458A8B39E04B4283D6C13C1"}}
        //{"data":{"certificates_v2":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900,"brand_ticket_amount":0},"encrypted_code":"CgYIASAHKAESLgossNFJYxtsv9+Ypz6s5ivQA5h4R3QEV954UNwqqqPXMEzoPmEIG+jX2hkHRTkaAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1}}],"description":"success","verify_token":"04a7c406-b691-4546-915a-172518196fb9","certificates":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900,"brand_ticket_amount":0},"encrypted_code":"CgYIASAHKAESLgosn9fhTseFQPRZdhHDbRb6efqnsAGtcQWgOtzbdOWo303mCDrsd9JaILbYv4saAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1}}],"error_code":0,"order_id":"1085870633719060487"},"extra":{"sub_error_code":0,"sub_description":"","description":"success","now":1749711395,"error_code":0,"logid":"20250612145635BD26F65681B37927C2AB"}}
        //{"data":{"certificates_v2":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900,"brand_ticket_amount":0},"encrypted_code":"CgYIASAHKAESLgosI7Qh8CFFMT/0Th7a1jcrV5buE4GC2AG8MUuLuvv74xtWifdZ7rBrC2urc/UaAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1}}],"description":"success","verify_token":"63b1d944-57ed-4746-8b92-f98ff57b83ca","certificates":[{"amount":{"coupon_pay_amount":9100,"platform_discount_amount":100,"pay_amount":9100,"merchant_ticket_amount":700,"list_market_amount":69900,"original_amount":9900,"brand_ticket_amount":0},"encrypted_code":"CgYIASAHKAESLgos7d6QtQDpJMTCsnQ7SBzLEvcw/lv/6Qjg3dlUZnfbDqrXnNuIiBjDaj7DCrYaAA==","expire_time":1780847999,"book_info":{"book_poi_id":"0"},"certificate_id":7514951884060278821,"start_time":1749711088,"sku":{"third_sku_id":"","sku_id":"1834504829123608","title":"【学生专属】单次卡+99代1000代金券 618大促专属优惠（限长沙新用户）","account_id":"7011378472920713250","sold_start_time":1749456127,"groupon_type":1,"market_price":69900},"use_time_info":{"use_time_type":1}}],"error_code":0,"order_id":"1085870633719060487"},"extra":{"sub_error_code":0,"sub_description":"","description":"success","now":1749711433,"error_code":0,"logid":"20250612145713AAE168C2B437B483B0F4"}}

        //验券();

        //来客门店列表();
        //解析抖音来客的通知();

        //查询订单可用门店(); -- 这是小程序的应用，用不了
    }

    private static void 查询订单可用门店(){
        String url = "https://open.douyin.com/api/trade/v2/fulfillment/order_can_use/";
        JSONObject header = new JSONObject();
        header.set("access-token",postRequestWithSign());
        header.set("content-type","application/json");
        header.set("Rpc-Transit-Life-Account", "7011378472920713250");
        JSONObject body = new JSONObject();
        body.set("order_id", "1086289107384980487");
        //body.set("verify_id","7517204613410474038");
        body.set("poi_id", "7312001208142317578");
        HttpUtils.sendPost(url,header, body);//可重复调用-都会返回成功
    }
    private static void 撤销核销(String certificate_id, String verify_id) throws Exception {
        String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/cancel/";
        JSONObject header = new JSONObject();
        header.set("access-token",postRequestWithSign());
        JSONObject body = new JSONObject();
        body.set("certificate_id", certificate_id);
        //body.set("verify_id","7517204613410474038");
        body.set("verify_id", verify_id);
        HttpUtils.sendPost(url,header, body);//可重复调用-都会返回成功
        //{"data":{"error_code":0,"description":"success"},"extra":{"error_code":0,"description":"success","sub_error_code":0,"sub_description":"","logid":"202506181637354B28480DD64B036294BA","now":1750235856}}
    }

    public static void 来客门店列表() {
        String url = "https://open.douyin.com/goodlife/v1/shop/poi/query?account_id=7011378472920713250&page=1&size=50";
        Map<String,String> header = new HashMap<>();
        header.put("access-token",postRequestWithSign());
        JSONObject result = HttpUtils.doGet(url,header);
        System.out.println(result);
    }
    public static void 查询订单券状态(String orderId) {
        String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/query/?order_id="+orderId;
        Map<String,String> header = new HashMap<>();
        header.put("access-token",postRequestWithSign());
        JSONObject result = HttpUtils.doGet(url,header);
        System.out.println(result);
    }
    public static void 验券准备(String code) {
        //String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/prepare/?account_id=7011378472920713250&code=1689350400&poi_id=1689956942";
        String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/prepare/?";
        //url = url + "encrypted_data=CgYIASAHKAESLgos748nqt7vFl3KsO1V9ynkOmtnGEhJ4bC1veSPT5xv5BPNzCj5LWET+11chhgaAA==";
        url = url + "code="+code;
        //url = url + "&poi_id=7312001208142317578";
        Map<String,String> header = new HashMap<>();
        header.put("access-token",postRequestWithSign());
        JSONObject result = HttpUtils.doGet(url,header);
        System.out.println(result);
        //{"data":{"description":"所选门店不在商品适用门店内","verify_token":"","error_code":3000002},"extra":{"sub_error_code":2065000126,"sub_description":"所选门店不在商品适用门店内","description":"所选门店不在商品适用门店内","now":1749794883,"error_code":3000002,"logid":"20250613140803E05F8D115715267B2068"}}
    }
    public static void 验券() {
        String url = "https://open.douyin.com/goodlife/v1/fulfilment/certificate/verify/?account_id=7011378472920713250&code=1689350400&poi_id=1689956942";
        Map<String,String> header = new HashMap<>();
        header.put("access-token",postRequestWithSign());
        JSONObject result = HttpUtils.doGet(url,header);
        System.out.println(result);
    }

    //订单查询
    private static void queryOrder(String orderId){
        String url = "https://open.douyin.com/goodlife/v1/trade/order/query/?account_id=7011378472920713250&page_num=1&page_size=10&order_id=" +orderId;
        Map<String,String> header = new HashMap<>();
        header.put("access-token",postRequestWithSign());
        JSONObject result = HttpUtils.doGet(url,header);
        System.out.println(result);
    }

    public static void increaseQuery () {
        //https://partner.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/info/query
        String url = "https://open.douyin.com/goodlife/v1/increase_value/order/query/?account_id=7011378472920713250&start_time=1689350400&end_time=1689956942&cursor=0&size=10";
        Map<String,String> header = new HashMap<>();
        header.put("access-token",postRequestWithSign());
        JSONObject result = HttpUtils.doGet(url,header);
        System.out.println(result);

    }

    public static void queryGoodsPage () {
        String url = "https://open.douyin.com/goodlife/v1/goods/product/online/query/?account_id=7011378472920713250";
        //?goods_creator_type=1&count=7455163376522312867&goods_query_type=1&poi_ids=[2702329537369200576]&Base={\"LogID\":\"S0q8Kb3YWr\",\"Caller\":\"N7KAtElRNE\",\"Addr\":\"wKbim0qaDM\",\"Client\":\"VaVpGSXgm4\",\"TrafficEnv\":{\"Env\":\"AKQsbGWlVW\",\"Open\":false},\"Extra\":{\"2LrUovq7Fl\":\"ml5RSapYzp\"}}&cursor=47UDWFLBp7&account_id=fSYx0sKt24&status=1&product_name=ykFbWdVLTf&query_all_poi=false&ext_ids=[6948154515539280481]'";
        Map<String,String> header = new HashMap<>();
        header.put("access-token",postRequestWithSign());
        JSONObject result = HttpUtils.doGet(url,header);
        System.out.println(result);//{"data":{"description":"应用未获商家授权","error_code":2119005}
    }
    public static void queryGoodsInfo () {
        String url = "https://open.douyin.com/goodlife/v1/goods/product/online/get/?account_id=7011378472920713250";
        //?goods_creator_type=1&count=7455163376522312867&goods_query_type=1&poi_ids=[2702329537369200576]&Base={\"LogID\":\"S0q8Kb3YWr\",\"Caller\":\"N7KAtElRNE\",\"Addr\":\"wKbim0qaDM\",\"Client\":\"VaVpGSXgm4\",\"TrafficEnv\":{\"Env\":\"AKQsbGWlVW\",\"Open\":false},\"Extra\":{\"2LrUovq7Fl\":\"ml5RSapYzp\"}}&cursor=47UDWFLBp7&account_id=fSYx0sKt24&status=1&product_name=ykFbWdVLTf&query_all_poi=false&ext_ids=[6948154515539280481]'";
        url = url + "&product_ids=1827013287391236";
        Map<String,String> header = new HashMap<>();
        header.put("access-token",postRequestWithSign());
        JSONObject result = HttpUtils.doGet(url,header);
        System.out.println(result);//{"data":{"description":"应用未获商家授权","error_code":2119005}
        //{"data":{"description":"","product_onlines":[{"product":{"category_full_name":"运动健身·健身房·私人健身房","creator_account_id":7011378472920713250,"owner_account_id":7011378472920713250,"product_name":"瘦美一夏【联系客服送礼品】私教9节+21天营养师 BMI≥20拍（江苏主页限定） ","version":1752048337915,"attr_key_value_map":{"can_no_use_date":"{\"enable\":false}","image_1v1_list":"[{\"url\":\"https://p3-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/6ea6b3dc72d0458fa881eeff1b774bdd?x-expires=1752152400\\u0026x-signature=TwhcsAlnu1Ij21l9HqolO6StmqA%3D\\u0026from=709197913\"},{\"url\":\"https://p3-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/64adea2ce5c24f2799a1fed3c5962d8d?x-expires=1752152400\\u0026x-signature=oz8c%2FJhKtstLsE7CnCB4lak3UJ4%3D\\u0026from=709197913\"}]","refund_rule":"{\"refund_type\":4,\"calc_price_type\":5}","PostPurchaseDay":"15","use_time":"{\"use_time_type\":1}","enable_multi_consume_once":"false","real_name_info":"{\"enable\":false,\"scene\":0}","Images":"[\"https://sf1-dycdn-tos.pstatp.com/obj/tos-cn-i-hf2m9xxmck/64adea2ce5c24f2799a1fed3c5962d8d\",\"https://sf1-dycdn-tos.pstatp.com/obj/tos-cn-i-hf2m9xxmck/27b5f5c705cc4db8908e52c9f560d94a\",\"https://sf1-dycdn-tos.pstatp.com/obj/tos-cn-i-hf2m9xxmck/d2764771e0e94d58a1ecb6772f9de2a6\"]","comsumption_threshold":"{\"enable\":false,\"description\":\"\"}","appointment":"{\"need_appointment\":true,\"ahead_time_type\":1,\"ahead_day_num\":3}","product_name":"瘦美一夏【联系客服送礼品】私教9节+21天营养师 BMI≥20拍（江苏主页限定） ","superimposed_discounts":"false","order_limit_rule":"{\"is_limit\":true,\"total_buy_num\":1}","auto_renew":"true","times_card_type":"0","description_rich_text":"[{\"note_type\":1,\"content\":\"\"},{\"note_type\":1,\"content\":\"此卡只针对减脂用户使用，BMI值低于20的客户不能使用，勿拍！！！\"},{\"note_type\":1,\"content\":\"此卡仅限健萌初次到店新客户体验使用，健萌老会员、已体验过的用户不可用；\"},{\"note_type\":1,\"content\":\"联系客服获得赠品：摇摇杯1个+枕头包1个；\"},{\"note_type\":1,\"content\":\"到店需联系客服提前3天预约，建议21天上完9节课，保证运动效果；\"},{\"note_type\":1,\"content\":\"9节课使用期间内全程有营养师一对一线上服务；\"},{\"note_type\":1,\"content\":\"如下单后遇到想去的门店已满载则不可使用，满载门店以咨询客服为准；\"},{\"note_type\":1,\"content\":\"此卡只能在同一家场馆固定同一位教练约课，不能跨场馆使用；\"}]","environment_image_list":"[{\"url\":\"https://p3-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/6c70d0451f7b417097bf0d16882cb6b8?x-expires=1752152400\\u0026x-signature=hW5cW8uprK9%2Bcp424%2FgbZEanI9w%3D\\u0026from=709197913\"},{\"url\":\"https://p3-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/450781cb3c7948e0a8313dda3215e7bc?x-expires=1752152400\\u0026x-signature=lpdYualfseoknZgLv8ZPUGIaf0E%3D\\u0026from=709197913\"},{\"url\":\"https://p26-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/3c8892513b30487db597fbd5e981f11b?x-expires=1752152400\\u0026x-signature=RjUzJEwCFYldMdpNkXbQwPDHNNQ%3D\\u0026from=709197913\"},{\"url\":\"https://p3-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/1d0f2a5970b84219acd33f98c3d2df7e?x-expires=1752152400\\u0026x-signature=6IMu0bhMt5%2F2Nig%2Ft5pBAOT%2FFU8%3D\\u0026from=709197913\"},{\"url\":\"https://p3-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/176c321b24ed48a480382d21e87a4c22?x-expires=1752152400\\u0026x-signature=%2F50c8mMY%2B0V82VJt4CVs6s%2F3b58%3D\\u0026from=709197913\"},{\"url\":\"https://p3-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/5d04117d1a7c4d48a5f6d05f78e6365b?x-expires=1752152400\\u0026x-signature=Zz0YpGX%2FpsNMaCcMnAMrX7%2F9QEg%3D\\u0026from=709197913\"},{\"url\":\"https://p3-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/2ea2254884d34af5a2091a44f0bd9b67?x-expires=1752152400\\u0026x-signature=akWW34zysy3H4fRaF5LYL2xCJ08%3D\\u0026from=709197913\"}]","show_channel":"1","product_qualification_union":"{}","DateRule":"{\"unavailable_date\":{\"date_list\":[],\"weekday_list\":[],\"not_available_on_holidays\":false}}","customer_reserved_info":"{\"allow\":true,\"allow_tel\":true,\"reserved_reason_type\":3}","enable_multi_user":"false","image_list":"[{\"url\":\"https://p11-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/64adea2ce5c24f2799a1fed3c5962d8d?x-expires=1752152400\\u0026x-signature=x91Q4qkczsk4hksw0vQgk7fk5lo%3D\\u0026from=709197913\"},{\"url\":\"https://p26-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/27b5f5c705cc4db8908e52c9f560d94a?x-expires=1752152400\\u0026x-signature=B2jOr1xxzYk0nsTqAY65zzlM7I0%3D\\u0026from=709197913\"},{\"url\":\"https://p11-sign.douyinpic.com/obj/tos-cn-i-hf2m9xxmck/d2764771e0e94d58a1ecb6772f9de2a6?x-expires=1752152400\\u0026x-signature=JQOOi2WxcrsiMDbIOt%2FDZ3uTtfc%3D\\u0026from=709197913\"}]","use_date":"{\"use_date_type\":2,\"day_duration\":15}"},"product_sub_type":0,"sold_end_time":1774954319,"product_type":15,"category_id":3005001,"sold_start_time":1744881180,"account_name":"长沙天萌体育发展有限公司","extra":"{\"TestFlag\":false,\"TestInfo\":{},\"boost_strategy\":\"{}\",\"create_source\":\"299467\",\"govern_rule_downgrade\":false,\"hermes_template_config_id\":\"7441565743592998948\",\"hermes_template_version\":\"1.0.4\",\"is_life_clue\":false,\"min_manage_account_id\":7011378472920713250,\"offline_info\":{\"OfflineReason\":\"违规上架周期卡商品\",\"OfflineVersion\":1751886538886,\"OperateRole\":\"SYSTEM\",\"Source\":\"life_governance\"},\"online_seat_selection_template\":false,\"operate_account_id\":7011378472920713250,\"operate_dept_id\":7448906621704718376,\"opt_app_key\":10148,\"opt_life_account_id\":7011378472920713250,\"opt_user_id\":1680473797172142,\"poi_count\":9,\"poi_set_id\":\"7524990043400800282\",\"pre_online_status\":\"OFFLINE\",\"service_item_template_snapshot_ids\":[],\"sku_count\":1,\"substitution_operation_reason\":\"\",\"template_id\":7506776002182285375,\"template_snapshot_ids\":[],\"tpl_publish_src\":\"OneStopV2\"}","product_id":"1827013287391236","pois":[{"supplier_ext_id":"6959676180647643140","poi_id":"6959676180647643140"},{"supplier_ext_id":"6968584222214735886","poi_id":"6968584222214735886"},{"supplier_ext_id":"7047810005373814822","poi_id":"7047810005373814822"},{"supplier_ext_id":"6849274580306003981","poi_id":"6849274580306003981"},{"supplier_ext_id":"7312001208142317578","poi_id":"7312001208142317578"},{"supplier_ext_id":"7002426393560631304","poi_id":"7002426393560631304"},{"supplier_ext_id":"7472688674218805248","poi_id":"7472688674218805248"},{"supplier_ext_id":"7001319085631866916","poi_id":"7001319085631866916"},{"supplier_ext_id":"6714798771642943492","poi_id":"6714798771642943492"}],"biz_line":1},"skus":[],"online_status":1,"commission_info":{"platform_take_rate":500},"sku":{"create_time":1752048338,"actual_amount":118000,"sku_id":"1827013287391236","attr_key_value_map":{"commodity":"[{\"group_name\":\"\",\"total_count\":4,\"option_count\":4,\"item_list\":[{\"name\":\"MPS运动评估筛查\",\"price\":0,\"count\":1,\"unit\":\"份\",\"item_id\":\"7350600566433761299\"},{\"name\":\"身体成份测试分析\",\"price\":0,\"count\":1,\"unit\":\"份\",\"item_id\":\"7350600044028250131\"},{\"name\":\"1对1私教课\",\"price\":0,\"count\":1,\"unit\":\"份\",\"item_id\":\"7350598666710992935\"},{\"name\":\"营养师服务\",\"price\":0,\"count\":1,\"unit\":\"份\",\"item_id\":\"7257703575160686631\"}]}]","settle_type":"3","consumption_times":"9","refund_description":"[{\"note_type\":1,\"content\":\"支持随时退，过期自动退\"},{\"note_type\":1,\"content\":\"整单退款：全部未使用，可随时退还全部实付金额\"},{\"note_type\":1,\"content\":\"剩余次数退款：发生核销后，剩余所有未核销次数须一起退款\"},{\"note_type\":1,\"content\":\"退款价格计算：可退金额=实付金额-购买时的单次划线价*已使用次数\"},{\"note_type\":1,\"content\":\"例如：3次卡实付¥300，购买时单次划线价为¥360/3次=¥120，使用2次后可退金额=¥300-¥120*2=¥60\"},{\"note_type\":1,\"content\":\"如有营销优惠，优惠金额将按比例计算后进行扣除\"}]","origin_amount_once":"37500","code_source_type":"1","order_limit_rule":"{\"is_limit\":true,\"total_buy_num\":1}","actual_amount_once":"13112","limit_buy_rule":"{\"enable_limit\":true,\"rule_list\":[{\"subject_type\":1,\"range_type\":3,\"limit_num\":1,\"unit\":\"张\"},{\"subject_type\":1,\"range_type\":4,\"limit_num\":1,\"unit\":\"张\"}]}","once_selling_price":"{\"amount_divide_type\":1,\"average_divided_amount\":13112}","order_settle_rule":"{\"order_settle_type\":2}","limit_rule":"{\"is_limit\":true,\"total_buy_num\":1}"},"update_time":1752049374,"origin_amount":337500,"sku_name":"瘦美一夏【联系客服送礼品】私教9节+21天营养师 BMI≥20拍（江苏主页限定） ","stock":{"limit_type":2,"stock_qty":10000000000},"status":1}}],"error_code":0},"extra":{"sub_error_code":0,"sub_description":"","description":"","now":1752133757,"error_code":0,"logid":"20250710154917D2BD52AEB8D3361B9C49"},"BaseResp":{"StatusCode":0,"StatusMessage":""}}

    }
    /**
     * 获取第三方平台的 AccessToken
     * @return
     * @throws Exception
     */
    public static String postRequestWithSign() {
        if("1".equals("")){
            return "clt.3671d7c5481f695da2665a5d8a094ac0T1aIzLOucJ6XwPLgwH40OEW4g1ce_lf";
        }
        JSONObject body = new JSONObject();
        body.set("client_key", "awu1dbdfx5yj4r5e");
        body.set("client_secret", "5706975dc56ff751fe60b16a797e8c01");//BTW测试店铺
        String sign = MD5.create().digestHex(body +"#Ts4MMhGqS5bmDlk4LNXk0xuJe1ycGsqU");
        JSONObject header = new JSONObject();
        header.set("X-SIGN",sign);
        header.set("X-TRACEID", UUID.randomUUID());
        header.set("X-APPKEY", "87377788520");
        JSONObject result = HttpUtils.sendPost("https://wedata.gymcity.com.cn/openapi/third/getDyLaiKeClientToken", header, body);
        //System.out.println(result);
        //System.out.println(result.getJSONObject("data").getStr("access_token"));
        return result.getJSONObject("data").getStr("access_token");
    }

    public static void 解析抖音来客的通知() throws IOException {
        FileReader fileReader = new FileReader("C:\\Users\\admin\\Desktop\\抖音来客的信息.txt");
        BufferedReader br = new BufferedReader(fileReader);
        String line = br.readLine();
        Set<String> set = new HashSet<>();
        for(;line!=null;line = br.readLine()){
            String str = line.substring(line.indexOf("param=>")+7);
            JSONObject jsonObject = new JSONObject(str);
            String content = jsonObject.getStr("content");
            JSONObject result = new JSONObject(content);
            set.add(result.getStr("action"));
            System.out.println(result);
        }
        System.out.println(set);
    }

}
